package com.example.anliku.controller;

import com.example.anliku.Utils.FileUtils;
import com.example.anliku.config.FileConfig;
import com.example.anliku.entity.Message;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@RequestMapping("/api/file")
@Api(tags = "全局文件上传模块")
public class FileController {

        @Resource
        private FileConfig config;

        @PostMapping("/")
        @ApiOperation(value = "文件上传，返回文件名数组")
        public Message fileUpload(MultipartFile[] files) throws IOException {
            if (files.length>0) {
                String rs= FileUtils.saveFileToTempDir(config.FilePath,config.hostUrl,files);
                return Message.success(null).add(rs);

            }
            return Message.fail("没有读取到您的上传文件信息");
        }


}
